package concurrent;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExecuteJob {
	
	public static void main(String[] args) {
		ExecutorService executorService = Executors.newFixedThreadPool(5);
		DataCollector dataCollector = DataCollector.getDateCollector();
		final CountDownLatch downLatch = new CountDownLatch(5);
		for(int i =0;i<5;++i){
			executorService.execute(new AbstractJob(i,dataCollector){

				@Override
				public void pre() {
					System.out.println("---job-begin--" + index);
				}

				@Override
				public void done() {
					downLatch.countDown();
					System.out.println("---job-finish--" + index);
				}
			});
		}
		
		try {
			System.out.println(downLatch.getCount());
			downLatch.wait();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}finally{
			executorService.shutdown();
		}
	}

}
